package com.sphd.beautysalon.adapters;

import android.widget.ImageView;

import com.android.volley.toolbox.ImageLoader;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sphd.beautysalon.R;
import com.sphd.beautysalon.base.RestaurantUrl;
import com.sphd.beautysalon.base.RestaurantsApplication;
import com.sphd.beautysalon.info.VipInfo;
import com.wzh.frame.utils.StringUtils;
import com.wzh.frame.utils.TimeUtils;
import com.wzh.frame.views.RoundImageView;

import java.util.List;

/**
 * Created by Hu on 2016/11/9.
 */

public class VipAdapter extends BaseQuickAdapter<VipInfo> {

    public VipAdapter(int layoutResId, List<VipInfo> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, VipInfo vipInfo) {
        baseViewHolder.setText(R.id.vip_name, StringUtils.isEmpty(vipInfo.getMem_name()) ? "未填写" : vipInfo.getMem_name())
                .setText(R.id.vip_registertime,StringUtils.isEmpty(vipInfo.getMem_phone())?"卡号:" + vipInfo.getMem_card()+"\n" +
                        "时间:" + ((vipInfo.getMem_regtime().indexOf("-")!=-1)
                        ?vipInfo.getMem_regtime():
                        TimeUtils.getTime(Long.parseLong(vipInfo.getMem_regtime()),TimeUtils.DEFAULT_DATE_FORMAT)):
                        "电话:" + vipInfo.getMem_phone());
        RoundImageView roundImageView = baseViewHolder.getView(R.id.vip_img);
        setImage(roundImageView, vipInfo.getMem_photo());

    }

    public void setImage(ImageView image, String url) {
        ImageLoader imageLoader =RestaurantsApplication.getImageLoader();
        ImageLoader.ImageListener listener = ImageLoader.getImageListener(image,
                R.mipmap.p, R.mipmap.p);
        imageLoader.get(RestaurantUrl.Httpimg + url, listener);
    }
}
